package com.externalizable.demo1;

import java.io.FileInputStream;
import java.io.FileOutputStream;
import java.io.IOException;
import java.io.ObjectInputStream;
import java.io.ObjectOutputStream;

public class Test {

	public static void main(String[] args) throws IOException, ClassNotFoundException {
		Blip1 b1 = new Blip1();
		Blip2 b2 = new Blip2();

		ObjectOutputStream o = new ObjectOutputStream(new FileOutputStream("blips.out"));
		o.writeObject(b1);
		o.writeObject(b2);
		o.close();

		ObjectInputStream in = new ObjectInputStream(new FileInputStream("blips.out"));
		// 恢复b1后，会调用Blip1的默认构造器，这与恢复Serializable对象不同，对于Serializable完全以它存储的二进制为基础来构造，而不是调用构造器
		b1 = (Blip1) in.readObject();
		// Blip2的构造函数不是公共的，会有异常
		// b2 = (Blip2) in.readObject();
	}

}
